$(function () {
var objslide;

    //var is_slide_on = false;
var pathtools = {
    getQueryString:function (name) { 
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
var r = window.location.search.substr(1).match(reg); 
if (r != null) return unescape(r[2]); return null; 
}, 
        slider_start:function(){
            clearInterval(objslide);
       imgLen = $("#slider-box ul li").length;
       var curIndex=0;
       // console.log(imgLen);
        objslide = setInterval(function(){
       //console.log("当前索引:"+curIndex);
            if(curIndex < imgLen-1){ 
    curIndex ++; 
  }else{ 
    curIndex = 0;
  }
  //调用变换处理函数
  pathtools.changeTo(curIndex); 
        },3000);
        },
    	menubar_refresh:function(){
    		
    		var hash;
    		if (hash = "/client" ){
    			//alert(location.hash);
    			$('#menubar').find(str).click();
    		}	
    	},
    onslide:function(){
            $('#slider-box').touchSlider({
                    box: '#slider-box',
                    arrow: false,
                    auto: true,
                    autoTime: 3000
                        });

                     },
    changeTo:function (num){ 
        //console.log("执行目标函数");
        $("#slider").find("li").eq(num).addClass('active').siblings('.active').removeClass('active');
      }

    }
	//定义路由器pathjs
	//首先Path.map("#/跳转路径名").to(function()){执行目标函数}
	//例如http://127.0.0.1/#/index
	//然后Path.root("#/跳转路径名")定义默认访问路径,在不指定路径时,默认访问的路径
	//例如设置path.root("#/about")访问http://127.0.0.1/时,会自动跳转到http://127.0.0.1/#/about
	//最后设置开始监听Path.listen()
	Path.map("#/index").to(function(){
        //alert("跳转主页index")
        var data = {
        	test:"测试变量index"

        };
        $('#container').html(Fxtpl.compile($('#tpl_index').html(),data));
        pathtools.slider_start();
        $('#index_con').on('click', '.list li', function () {
        	
            //$(this).addClass('active').siblings('.active').removeClass('active');
            var li_href=$(this).attr("href");
    		location.href=li_href;
    		//alert(li_href);
        })
       
    });
    Path.map("#/client").to(function(){
        alert(location.hash)
        var data = {
        	test:"测试变量client"

        };
        
        $('#container').html(Fxtpl.compile($('#tpl_client').html(),data));
       
        });
    Path.map("#/wx_login").to(function(){
        //alert(location.hash)
        var data = {
            test:"测试变量wx_login"

        };
        
        $('#container').html(Fxtpl.compile($('#tpl_wx_login').html(),data));
        window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx32ff322faf0ccbbd&redirect_uri=http://wc.1688368.com/tj_ui/index.html&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
        });
    Path.map("#/discover").to(function(){
        //alert("跳转主页discover")

        var data = {
        	test:"测试变量discover"

        };
        $('#container').html(Fxtpl.compile($('#tpl_discover').html(),data));
       location.herf="#/wx_login";
       var index = layer.open({
        content: '移动版和PC版不能同时存在同一页面4'
        ,btn: '我知道了'
        ,yes: function(index){
      //location.herf="#/wx_login";
     // alert(0);
      window.location.href="#/wx_login"
      layer.close(index);
      
    }
      });
    });
  
    Path.map("#/bbs").to(function(){
        //alert("跳转主页bbs")
        var data = {
        	test:"测试变量bbs"

        };
        $('#container').html(Fxtpl.compile($('#tpl_bbs').html(),data));
        $.ajax({
                    async: false,
                    url: 'http://127.0.0.1/tjadmin/index.php/MemberUser/Api/get_user_info',
                    dataType: 'jsonp',
                    type: 'get',
                    jsonp: '_c',
                    data: {
                        name:'123'
                        //InputPassword1: oldpwd,
                        //InputPassword2: loginpwd
                    },
                    success: function(data) {
                        //eval("var resp="+data);
                        console.log(resp);
                        console.log(resp.data);
                        if (resp) {
                            
                        }
                        else {
                            
                        }
                    },
                    error: function(errorMsg) {
                        console.log(errorMsg.responseText);
                    }
                    //console.log((eval(a).responseText));
                });
    });
      Path.map("#/my").to(function(){
        //alert("跳转主页my")
        var data = {
        	test:"测试变量my"

        };
        $('#container').html(Fxtpl.compile($('#tpl_my').html(),data));
       $.getJSON("U('MemberUser/Api/get_user_info')"
            ,function(result){
                  console.log(result.info);
                  if (result.status_code==0) {
                   var index = layer.open({
                    content: result.info
                    ,btn: '确定'
                    ,yes: function(index){
                  layer.close(index);
                  
                }
                 });
                  } else{
                    var index = layer.open({
                    content: '您已登录成功'
                    ,btn: '确定'
                    ,yes: function(index){
                  layer.close(index);
                  
                }
             });
              };
            });
    });
    
    Path.root("#/index");
    Path.listen(); 
    
    //主bar单击事件绑定
        $('#menubar').on('click', '.tab', function () {
        	
            $(this).addClass('active').siblings('.active').removeClass('active');
            var li_href=$(this).attr("href");
    		location.href=li_href;
    		//alert(li_href);
        })
//      .on('click','#menubar_index',function () {
//      	location.href="#/index"
//                 // opt_ajax.setting();
//          })
//      .on('click','#menubar_client',function () {
//      	location.href="#/client"
//                 // opt_ajax.setting();
//          })
//      .on('click','#menubar_discover',function () {
//      	location.href="#/discover"
//                 // opt_ajax.setting();
//          })
//      .on('click','#menubar_bbs',function () {
//      	location.href="#/bbs"
//                 // opt_ajax.setting();
//          })
//      .on('click','#menubar_my',function () {
//      	location.href="#/my"
//                 // opt_ajax.setting();
//          })
        
        
})